package com.upbos.upm.entity;

import com.upbos.data.persistence.annotation.Column;
import com.upbos.data.persistence.annotation.Id;
import com.upbos.data.persistence.annotation.IdType;
import com.upbos.data.persistence.annotation.Table;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
@Table("upm_module")
public class Module implements Serializable, Comparable<Module>, Cloneable {

    private static final long serialVersionUID = 123122L;

    public Module() {

    }

    public Module(String id, String name, String icon, String cascade) {
        this.id = id;
        this.name = name;
        this.icon = icon;
        this.cascade = cascade;
    }

    /**
     * 功能模块Id
     */
    @Id(idType = IdType.AUTO)
    private String id;

    /**
     * 资源标识
     */
    @Column("key_")
    private String key;

    /**
     * 功能模块名称
     */
    @Column("name")
    private String name;

    /**
     * 资源url
     */
    @Column
    private String url;


    /**
     * 层级代码
     */
    @Column("cascade_")
    private String cascade;

    /**
     * 描述
     */
    @Column
    private String remark;

    /**
     * 上级功能模块Id
     */
    @Column("parent_id")
    private String parentId;

    /**
     * 图标
     */
    @Column
    private String icon;

    /**
     * 是否弹出
     */
    @Column("is_embed")
    private Boolean isEmbed;

    /**
     * 是否自动运行
     */
    @Column("is_autorun")
    private Boolean isAutorun;

    private Boolean isLeaf;

    /**
     * 是否固定
     */
    private Boolean isFixed;

    @Column
    private Boolean status;
    /**
     * 排序号
     */
    @Column
    private Integer idx;

    /**
     * 所属系统
     */
    @Column("app_id")
    private Integer appId;

    /**
     * 下级功能模块列表
     */
    private List<Module> children;

    /**
     * 所属资源列表
     */
    private List<ModuleRes> resList;

    @Override
    public int compareTo(Module o) {
        return this.idx.compareTo(o.idx);
    }

    @Override
    public boolean equals(Object obj) {
        return this.id.equals(((Module) obj).id);
    }

    @Override
    public Module clone() {
        try {
            return (Module) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}
